package cn.taokuaidi.wangwang.client.model;

import java.util.List;

import cn.taokuaidi.wangwang.client.context.AgentEventContext;

import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.store.ListStore;

public class ExpressDO extends BaseModelData {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public String getAgentId() {
        if (get("agent_id") != null) {
            return get("agent_id").toString();
        }
        return null;
    }

    public boolean isEnd() {
        return get("is_end");
    }

    public boolean isNotExist() {
        return get("not_exist");
    }

    public String getNo() {
        return get("no_code");
    }

    public List<StatusInfo> getStatuses() {
        return get("statuses");
    }

    public void setStatuses(List<StatusInfo> statuses) {
        set("statuses", statuses);
    }

    public String getConsumeTime() {
        List<StatusInfo> infos = getStatuses();
        if (infos == null || infos.size() == 0) return "";
        StatusInfo startInfo = infos.get(0);
        return startInfo.getHappenTime();
    }

    /**
     * 获得隶属的快递公司名称,系统加载后只允许一次
     */
    public AgentDO getAgent() {
        AgentDO retVal = get("agent");
        if (retVal == null) {
            String agent_id = getAgentId();
            ListStore<AgentDO> sourceList = AgentEventContext.getStore();
            for (int i = 0; i < sourceList.getModels().size(); i++) {
                AgentDO aimAgent = sourceList.getModels().get(i);
                if (aimAgent != null && agent_id.equalsIgnoreCase(aimAgent.getId())) {
                    setAgent(aimAgent);
                    return aimAgent;
                }
            }
        }
        return retVal;
    }

    public void setAgent(AgentDO agent) {
        set("agent", agent);
    }

}
